package com.tulingxueyuan.mall.modules.pms.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tulingxueyuan.mall.common.api.CommonPage;
import com.tulingxueyuan.mall.common.api.CommonResult;
import com.tulingxueyuan.mall.dto.PmsProductArrtbuteDTO;
import com.tulingxueyuan.mall.modules.pms.model.PmsProductAttribute;
import com.tulingxueyuan.mall.modules.pms.model.PmsProductAttributeCategory;
import com.tulingxueyuan.mall.modules.pms.service.PmsProductAttributeCategoryService;
import com.tulingxueyuan.mall.modules.pms.service.PmsProductAttributeService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 产品属性分类表 前端控制器
 * </p>
 *
 * @author XuShu
 * @since 2023-05-08
 */
@RestController
@RequestMapping("/productAttribute/category")
public class PmsProductAttributeCategoryController {
    @Resource
    private PmsProductAttributeCategoryService pmsProductAttributeCategoryService;

    @GetMapping("/list")
    @ApiOperation("商品属性分类列表")
    public CommonResult<CommonPage<PmsProductAttributeCategory>> list(
            @RequestParam(value = "pageNum",required = false,defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize",required = false,defaultValue = "5") Integer pageSize){
        Page page =  pmsProductAttributeCategoryService.listPage(pageNum,pageSize);
        return CommonResult.success(CommonPage.restPage(page));
    }

    @GetMapping("list/withAttr")
    @ApiOperation("获取商品分类的属性")
    public CommonResult<List<PmsProductArrtbuteDTO>> listWithAttr(){
        List<PmsProductArrtbuteDTO> listWithAttrbute =  pmsProductAttributeCategoryService.listWithAttrbute();
        return CommonResult.success(listWithAttrbute);
    }


    @PostMapping("/create")
    @ApiOperation("添加商品分类属性")
    public CommonResult add(PmsProductAttributeCategory pmsProductAttributeCategory){
        boolean b =  pmsProductAttributeCategoryService.add(pmsProductAttributeCategory);
        return CommonResult.success(b);
    }

    @PostMapping("/update/{id}")
    @ApiOperation("修改商品分类属性")
    public CommonResult update(PmsProductAttributeCategory pmsProductAttributeCategory){
        boolean b =  pmsProductAttributeCategoryService.updateById(pmsProductAttributeCategory);
        return CommonResult.success(b);
    }

    @GetMapping("/delete/{id}")
    @ApiOperation("删除商品分类属性")
    public CommonResult delete(PmsProductAttributeCategory pmsProductAttributeCategory){
        boolean b =  pmsProductAttributeCategoryService.removeById(pmsProductAttributeCategory);
        return CommonResult.success(b);
    }
}

